"""
@Project:Python crawler
@File:希尔排序耗时计算.py
@Author:邓建祥
@Date:9:36
"""

import random,time

aa = random.randint(10,100)
aa_list = []
for i in range(1,10):
    aa = random.randint(10, 100)
    aa_list.append(aa)

print(aa_list)



# 希尔排序
def shell_sort(arr):
    # 取整计算增量（间隔）值
    gap = len(arr) // 2
    while gap > 0:
        # 从增量值开始遍历比较
        for i in range(gap, len(arr)):
            j = i
            current = arr[i]
            # 元素与他同列前面的元素比较，如果比前面的小则互换，其实，这就是插入排序
            while j - gap >= 0 and current < arr[j -gap]:
                arr[j] = arr[j - gap]
                j -= gap
            arr[j] = current
            # 缩小增量（间隔）值
        gap //= 2
    return arr
timeenfd = time.perf_counter()

sorted_arr = shell_sort(aa_list)
print("希尔排序>",sorted_arr)
print(timeenfd)